<?php

/**
 * forms the combobox by given items
 * @author		ungerboeck simon <ungerboeck_simon@hotmail.com>
 *
 */
class Combobox {
	public static function createCombo($name, $items, $valueFunc, $selectedId = null, $params = array()){
		$combo = array(NULLITEM_VALUE => NULLITEM);
		foreach ($items as $item)
			$combo[$item->id] = $valueFunc($item);
		return \Form::select($name, $combo, $selectedId, $params);
	}
}


/**
 * creates the combobox for salutations
 * @author		ungerboeck simon <ungerboeck_simon@hotmail.com>
 *
 */
class SalutationCombo extends Combobox{
	public static function create($name, $selectedId = null, $params = array()) {
		$items = Salutation::all()->sortBy(function ($salutation) {
			return $salutation->translation->getTranslation();
		});

		return parent::createCombo($name, $items, function($salutation){
			return $salutation->translation->getTranslation();
		}, $selectedId, $params);
	}
}


/**
 * creates the combobox for countries
 * @author		ungerboeck simon <ungerboeck_simon@hotmail.com>
 *
 */
class CountryCombo extends Combobox{
	public static function create($name, $selectedId = null, $params = array()) {
		$items = Country::orderBy('name')->get();

		return parent::createCombo($name, $items, function($country){
			return $country->name;
		}, $selectedId, $params);
	}
}

?>